cc.Class({
  extends: cc.Component,

  properties: {



    excludeName: "", //排除掉的app名称

    // jsonUrl:"https://www.77xyz.xyz/gameres/apps/apps.json",

  },

  // LIFE-CYCLE CALLBACKS:

  onLoad() {
G.APPS=this;
    this.prefab = this.node.children[0];
    this.node.removeAllChildren();

  },

  start() {


    // try {


    //   // let jsonUrl = window.NetConfig.appsurl;
    //   cc.log("加载jsonUrl", this.jsonUrl)
    //   cc.loader.load(this.jsonUrl, (err, res) => {

    //     if (err) {
    //       cc.log("加载jsonUrl err", err);
    //       return;
    //     }
    //     cc.log("加载jsonUrl res", res);

    //     this.init(res);

    //   });

    // } catch (e) {
    //   cc.error(e);
    // }

    // this.init();
  },

  init() {


    for (let i in G.netConfig.wx.apps) {

      try {
        let app = G.netConfig.wx.apps[i];
        if (app.name == this.excludeName) {
          continue;
        }

        let node = cc.instantiate(this.prefab);

        node.getChildByName("nameLabel").getComponent(cc.Label).string = app.name + "";

        let icon = node.getChildByName("icon").getComponent(cc.Sprite);


        cc.loader.load(app.icon, function (err, texture) {
          icon.spriteFrame = new cc.SpriteFrame(texture);
        });

        node.on("touchstart", () => {
          this.jump(app);
        });


        this.schedule(() => {

          node.runAction(cc.shake(1.5, 8, 8));

        }, 10, cc.macro.REPEAT_FOREVER, 1);


        node.parent = this.node;

      } catch (e) {
        cc.error(e);
      }

    }

  },

  jump(app) {

    wx.navigateToMiniProgram({
      appId: app.appId,
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })

  },

  // update (dt) {},
});